const moment = require('moment')
// const chalk = require('chalk')
const log4js = require('log4js')

log4js.configure({
  appenders: {
    common: {
      type: 'file',
      filename: `log4js/system-log.${moment().format('YYYY-MM-DD')}.log`,
      layout: {
        type: 'pattern',
        pattern: '[%d{yyyy-MM-dd hh:mm:ss}] [%p] %c - %m',
      }
    }
  },
  categories: {
    default: { appenders: ['common'], level: 'info' },
    error: { appenders: ['common'], level: 'error' }
  }
})

module.exports = {
  logError (msg) {
    const logger = log4js.getLogger('error')
    logger.error(msg)
  },
  logInfo (msg) {
    const logger = log4js.getLogger()
    logger.info(msg)
  }
}